feat(protect): broaden Express body-parser recognition - #90
Merged
Conversation
The egress guard screened outbound calls by hostname, so a name that passes the check but resolves to an internal/metadata IP (DNS rebinding, or just a hostname pointing inward) slipped through. On the Node http/https path, inject a screening DNS `lookup` into the request options: resolve the hostname, run each resolved address through the same egress predicate (so `internal_host` rules + allowlist apply to the IP too), block if any is disallowed, and pin the connection to the vetted resolution — closing the time-of-check/time-of-use gap. Only for real hostnames (literal IPs are already covered by the sync check). Default on via `screenDns` (disable with `screenDns: false`); needs node:dns/net, so it's a no-op on edge runtimes, where hostname rules still apply. Fail-open: a resolver or injection error proceeds unscreened rather than breaking the request. `lookup` is injectable for tests. The fetch/undici path is intentionally left for a follow-up. +5 tests, 495 total, typecheck (incl. template check) + build clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Express adapter only anchored on `express.json()`, so apps using `express.urlencoded()`, body-parser (`bodyParser.json()`/`.urlencoded()`), an aliased parser, or a destructured `json()` were scaffolded but left unwired. Broaden the anchor to any `app.use(<x>.json(|urlencoded()` (or a bare `json(`/`urlencoded(`), so the guard wires after whichever parser populates req.body. No-parser apps are still intentionally left not-wired (the guard reads the parsed body). +3 tests, 497 total. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Extended regex elegantly detects various body-parser invocations. 🎯 Quality: 100% Elite · 📦 Size: Small 📈 This month: Your 39th PR — above team average · Averaging Excellent |
Contributor
Author
|
/review |
ejntaylor
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #89. The Express adapter only anchored on
express.json(), so apps usingexpress.urlencoded(), body-parser (bodyParser.json()/.urlencoded()), an aliased parser, or a destructuredjson()were scaffolded but left unwired (--checkreported not-wired).Broaden the anchor to any
app.use(<x>.json(|urlencoded()— or a barejson(/urlencoded(— so the guard wires right after whichever parser populatesreq.body. No-parser apps are still intentionally left not-wired (the guard reads the express-parsed body; there's nothing to inspect without a parser).+3 tests (urlencoded, body-parser, destructured json), 498 total. Comment/regex + tests only; no template or disclosure change.